#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>

const int N = 100010;

int p[N];
int n, m;

int find(int u)
{
    if (p[u] != u)   p[u] = find(p[u]);
    return p[u];
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)   p[i] = i;
    while (m--)
    {
        int a, b;
        char op[2];
        scanf("%s%d%d", &op, &a, &b);
        if (*op == 'M')
        {
            int p1 = find(a), p2 = find(b);
            if (p1 != p2)    p[p1] = p2;
        }
        else
        {
            int p1 = find(a), p2 = find(b);
            if (p1 == p2)    puts("Yes");
            else puts("No");
        }
    }
    return 0;
}